package flc.ast.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyCalendarBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class CalendarAdapter extends StkProviderMultiAdapter<MyCalendarBean> {

    public CalendarAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(60));
        addItemProvider(new CalendarProvider());
    }

    private class CalendarProvider extends BaseItemProvider<MyCalendarBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_calendar;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyCalendarBean bean) {
            baseViewHolder.getView(R.id.tvCalendarItemLog).setVisibility(View.VISIBLE);
            baseViewHolder.setText(R.id.tvCalendarItemDate, bean.getDate());
            if (bean.isSelect()) {
                baseViewHolder.setTextColor(R.id.tvCalendarItemDate, Color.parseColor("#FFFFFF"));
                baseViewHolder.setBackgroundResource(R.id.tvCalendarItemLog, R.drawable.rl_2);
            } else {
                baseViewHolder.setTextColor(R.id.tvCalendarItemDate, Color.parseColor("#0F3C73"));
                baseViewHolder.getView(R.id.tvCalendarItemLog).setBackground(null);
            }
            if (bean.isRecord()) {
                baseViewHolder.getView(R.id.tvCalendarItemLog).setVisibility(View.VISIBLE);
                if (bean.isSelect()) {
                    baseViewHolder.setBackgroundResource(R.id.tvCalendarItemLog, R.drawable.rl_2);
                } else {
                    baseViewHolder.setBackgroundResource(R.id.tvCalendarItemLog, R.drawable.rl_1);
                }
            }
            if (TextUtils.isEmpty(bean.getDate())) {
                baseViewHolder.getView(R.id.tvCalendarItemDate).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.tvCalendarItemLog).setVisibility(View.GONE);
            }
        }
    }
}
